package link.gpt.service.impl;

import link.gpt.dao.AnswersDao;
import link.gpt.pojo.Answers;
import link.gpt.pojo.AnswersExample;
import link.gpt.service.AnswersService;
import link.gpt.service.QuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @version V1.0A
 * @uthor gpt
 * @Project holiday_task
 * @Package link.gpt.service.impl
 * @Description: ${TODO}
 * @Date 2021/10/7 17:01
 */
@Service
public class AnswersServiceImpl implements AnswersService {
   @Autowired
   private AnswersDao answersDao;

   @Autowired
   private QuestionService questionService;

   @Override
   public List<Answers> findAllByQid(Integer qid) {
      AnswersExample example = new AnswersExample();
      AnswersExample.Criteria criteria = example.createCriteria();
      criteria.andQidEqualTo(qid);
      return answersDao.selectByExample(example);
   }

   @Override
   public int addAns(Answers answers) {
      int count = answersDao.insertSelective(answers);
      if (count == 1) {
         questionService.updateQuestionAnsCount(answers.getQid());
      }
      return count;
   }
}
